#include "Base.h"
#include "WorldPlayer.h"
#include "Log.h"
#include "LWProtocol.h"
#include "LobbyProtocol.h"
#include "LobbyClientPlayer.h"
#include "LobbyServer.h"
#include "GameProtocol.h"

CWorldPlayer *g_pWorldPlayer = NULL;

CWorldPlayer::CWorldPlayer(void)
{
}

CWorldPlayer::~CWorldPlayer(void)
{
}

BOOL CWorldPlayer::OnInitialUpdate(const char *szServerIP, int nPort, int nOrigin, int nServerId)
{
	if(!CServerPlayer::OnInitialUpdate(szServerIP, nPort, nOrigin, nServerId))
	{
		WriteLog("%s : %d CWorldPlayer::OnInitialUpdate return FALSE", __FILE__, __LINE__);
		return FALSE;
	}
	g_pWorldPlayer = this;
	return TRUE;
}

Msg* CWorldPlayer::CreateMsg(DWORD dwMsgId, int nLen)
{
	switch(dwMsgId)
	{
	case Msg_WL_User_SignInfo:
		return new WLUserSignupInfoMsg;
	default:
		break;
	}
    return NULL;
}

BOOL CWorldPlayer::OnMsg(Msg *pMsg)
{
	DWORD dwMsgId = pMsg->GetMsgId();
	switch(dwMsgId)
	{
	case Msg_WL_User_SignInfo:
		{
            OnUserSignInfo((WLUserSignupInfoMsg*)pMsg);
			break;
		}
	default:
		break;
	}
    return TRUE;
}

BOOL CWorldPlayer::OnUserSignInfo(WLUserSignupInfoMsg *pMsg)
{
    CLobbyClientPlayer *pClientPlayer = g_pLobbyServer->FindClientPlayer(pMsg->m_dwUserId);
	if(pClientPlayer != NULL)
	{
		LCSignupInfoMsg msg;
		msg.m_listSignupInfo.CloneFrom(pMsg->m_listSignupInfo);
        pClientPlayer->SendMsg(&msg);
	}
	return TRUE;
}


